using System;
using System.Collections.Generic;
using Spring.Data;
using Spring.Transaction;
using Spring.Transaction.Interceptor;
using Com.Easywiki.Model;
using Common.Logging;
using NHibernate;
using Spring.Stereotype;
using Spring.Data.NHibernate.Generic.Support;

namespace Com.Easywiki.DAO
{
	public interface ICategoryDAO{
		void Save(Category entity);
		IList<Category> LoadAllCategory();
	}

	public class CategoryDAO : HibernateDaoSupport, ICategoryDAO
	{
		ILog log = LogManager.GetLogger("Ravi");
		public CategoryDAO (){	}

		[Transaction(ReadOnly=false)]
		public void Save(Category entity){
			Session.SaveOrUpdate(entity);
		}

		public IList<Category> LoadAllCategory(){
			log.Debug("get Session ->" + Session);
			 ICriteria criteria = Session.CreateCriteria<Category>();
			return criteria.List<Category>() ;
		}

		public override string ToString ()
		{
			return string.Format ("[CategoryDAO: SessionFactory={0}, Session={1}]", SessionFactory, Session );
		}
		
	}
}